package com.itheima.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.SmsCouponMapper;
import com.itheima.mapper.SmsCouponProductCategoryRelationMapper;
import com.itheima.pojo.SmsCouponProductCategoryRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author lenovo
 * @description 针对表【sms_coupon_product_category_relation(优惠券和产品分类关系表)】的数据库操作Service实现
 * @createDate 2022-10-11 14:26:17
 */
@DubboService
public class SmsCouponProductCategoryRelationApiImpl implements SmsCouponProductCategoryRelationApi {
    @Autowired
    private SmsCouponProductCategoryRelationMapper couponProductCategoryRelationMapper;

    //保存couponProductCategoryRelation
    @Override
    public void saveCouponProductCategoryRelation(SmsCouponProductCategoryRelation productCategoryRelationList) {
        couponProductCategoryRelationMapper.insert(productCategoryRelationList);
    }

    //更新SmsCouponProductCategoryRelation对象
    @Override
    public void updateCouponProductCategoryRelation(SmsCouponProductCategoryRelation productCategoryRelationList) {
        couponProductCategoryRelationMapper.updateById(productCategoryRelationList);
    }

    //查找SmsCouponProductCategoryRelation
    @Override
    public SmsCouponProductCategoryRelation findByCouponId(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(couponId), SmsCouponProductCategoryRelation::getCouponId, couponId);
        return couponProductCategoryRelationMapper.selectOne(lqw);
    }

    //根据couponId删除productCategoryRelation
    @Override
    public void deleteByCouponId(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(couponId), SmsCouponProductCategoryRelation::getCouponId, couponId);
        couponProductCategoryRelationMapper.delete(lqw);
    }


}




